package com.morizhang.merchanmanager.api.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.morizhang.merchanmanager.api.ApiResult;
import com.morizhang.merchanmanager.api.IService;
import com.morizhang.merchanmanager.api.model.CommodityWareModel;
import com.morizhang.merchanmanager.api.plugins.BasicWareManage;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.Method;
import java.util.List;

@ServiceAnnotation(name = "QueryCommodityByLocationService")
public class QueryCommodityByLocationService implements IService {

    @Autowired
    BasicWareManage basicWareManage;

    @Override
    public ApiResult callService(JSONObject requestParams) throws Exception {
        String callMethodName = requestParams.getString("requestMethod");
        Method callMethod = this.getClass().getMethod(callMethodName, JSONObject.class);
        ApiResult result = (ApiResult)callMethod.invoke(this, requestParams);
        result.setSuccess(true);
        return result;
    }

    public ApiResult queryCommodityByWarehouseShelfNo(JSONObject requestParams) {
        List<CommodityWareModel> searchResult = basicWareManage.queryWarehouseShelfCommodityInfo(requestParams.getJSONObject("data").getString("warehouseShelfNo"));
        ApiResult result = new ApiResult();
        result.setData(JSONArray.parseArray(JSON.toJSONString(searchResult)));
        return result;
    }

    public ApiResult queryCommodityByShopShelfNo(JSONObject requestParams) {

        return null;
    }
}
